package com.douqu.game.core.config.store;

import com.douqu.game.core.config.common.CommonData;
import com.douqu.game.core.config.common.GoodsData;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.factory.DataFactory;
import com.douqu.game.core.factory.LoadFactory;
import com.douqu.game.core.util.LogUtils;

/**
 * @author wangzhenfei
 *         2017-10-28 17:15
 */
public class Store extends GameObject{

    public int storeType;
    /**
     *  商品
     */
    public GoodsData goods;
    /**
     * 价格
     */
    public CommonData price;
    /**
     * 刷新概率
     */
    public int rate;

    /**
     * 折扣
     */
    public int discount;



    @Override
    public boolean check()
    {
        if(goods == null)
        {
            LogUtils.error("Store check goods is null -> id:" + id + " name:" + name);
            return false;
        }

        if(price == null)
        {
            LogUtils.error("Store check price is null -> id:" + id + " name:" + name);
            return false;
        }
        return super.check();
    }


    @Override
    public boolean setVariable(String key, String value)
    {
        if("goods".equals(key))
        {
            goods =  new GoodsData(value);
            return goods.check(this.getClass(), key, id);
        }else if("price".equals(key))
        {
            price =  new CommonData(value);
            if(DataFactory.getInstance(LoadFactory.isTestLoad()).getGameObject(DataFactory.ASSET_KEY, price.id) == null)
            {
                LogUtils.error("GoblinStore setVariable price Error -> type : " + goods.type + " id:" + goods.id + " num:" + goods.value);
                return false;
            }
            return true;
        }
        else
            return super.setVariable(key, value);
    }

    @Override
    public String toString() {
        return "Store{" +
                "goods=" + goods +
                ", price=" + price +
                "} " + super.toString();
    }
}
